package com.wuage.infrastructure.security;

import com.wuage.infrastructure.status.BizResultCode;
import com.wuage.infrastructure.utils.OpenGsonWrapper;
import com.wuage.infrastructure.utils.Response;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Shynin
 * @version 1.0
 * @date 2020-09-03 01:44
 */
public class JwtAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        response.getWriter().write(OpenGsonWrapper.toJson(new Response<>(BizResultCode.NOT_PERMISSION)));
    }
}
